/**
 * Created by Administrator on 2018/1/15.
 */
define(function(require, exports, module) {
    var $=require('zepto');
        cn=require('conment');
        drop=require('dropload');
        api=require('api')
    module.exports = {
        int:{
            pageNo:1,
            pageSize:10,
            isTime:false
        },

        waterAjax:function (me) {
            const _this=this;
            cn.Ajax(api.water,{page:_this.int.pageNo,Length:_this.int.pageSize},function(c){
                const water=new Array();
                const list=c.list;
                if(_this.int.pageNo==0&&list.length<_this.int.pageSize-1){
                    $('.dropload-down').hide()
                }
                if(_this.int.pageNo==0&&list.length==0){
                    $("#water_list").html('<div class="zwsj" ><img src="../../images/home/kong.png"><p>搭档出本金，买卖你做主</p><a href="/view/seach.html">立即发起交易</a></div>');
                    $('.dropload-down').hide()
                    me.resetload();
                    return false
                }
                if(_this.int.pageNo&&list.length<=0){
                    // $('.dropload-down').hide()
                    me.noData();
                }
                $.each(list,function(i,l,array){
                    water.push('<li>');
                    water.push('<div class="left-y"><span class="'+(l.useType==1?'red':'green')+'"></span></div>');
                    water.push('<div class="content-list">');
                    water.push('<p><span class="txt">'+l.descr+'</span><span class="rt '+(l.useType==1?'red':'green')+'">'+l.amount+'</span></p>');
                    water.push('<p><span>'+(l.timeStr)+'</span><span class="rt">'+l.useTypeStr+'</span></p>');
                    water.push('</div>');
                    water.push('</li>');
                    _this.int.pageNo++
                });
                // 为了测试，延迟1秒加载
                setTimeout(function () {
                    $('#water_list ul').append(water.join(''));
                    me.resetload();
                }, 500);
            },'post')
        },
        upDown:function () {
            const _this=this;
            var dropload = $('#view-content').dropload({
                scrollArea : window,
                threshold:100,
                loadUpFn : function(me){
                    _this.int.pageNo=1;
                    $('#water_list ul').html('');
                    _this.waterAjax(me)

                },
                loadDownFn : function(me){
                    _this.waterAjax(me)
                }
            });
        },
        init:function () {
            const _this=this;
            _this.upDown()
        },
    }

});

